package com.elm.util;

public class PageUtil {
	public static String  getPage(int totalNum,int currentPage,int pageSize){
		int totalPage = totalNum%pageSize==0?totalNum/pageSize:totalNum/pageSize+1;
		StringBuffer page =  new StringBuffer();
		page.append("<li><a href='enterusermain?page=1'>首页</a></li>");
		if(currentPage==1){
			page.append("<li class='disabled'><a href='#'>上一页</a></li>");
		}else{
			page.append("<li><a href='enterusermain?page="+(currentPage-1)+"'>上一页</a></li>");
		}
		//生成页码     当前页 2        0                  4
		for (int i = currentPage-2; i < currentPage+2; i++) {
				if(i<1||i>totalPage){
					continue;
				} 
				if(i==currentPage){
					page.append("<li class='active'><a href='#'>"+i+"</a></li>");
				}else{
					page.append("<li><a href='enterusermain?page="+i+"'>"+i+"</a></li>");
				}
		}
		if(currentPage==totalPage){
			page.append("<li class='disabled'><a href='#'>下一页</a></li>");
		}else{
			page.append("<li><a href='enterusermain?page="+(currentPage+1)+"'>下一页</a></li>");
		}
	
		
		page.append("<li><a href='enterusermain?page="+totalPage+"'>尾页</a></li>");
		return  page.toString();
	}
}
